<template>
	<div class="diglog-info streetEdit projectDialog">
		<el-dialog title="编辑" :visible.sync="dialogVisible" size='small'>
			<el-tabs>
				<el-tab-pane label="督办情况">
					<el-form :model="dataAll" :rules="rules" ref="dataAll" label-width="0" class="demo-ruleForm">
						<div v-if="dataAll" class="zui-noFloat">
							<el-row :gutter="80">
								<el-col :span="24">
									<el-form-item prop="workContent">
										<div class="content">
											<my-tooltip text="督办情况"></my-tooltip>
											<div class="desc-input">
												<el-input v-model="dataAll.workContent" type="textarea" placeholder="请输入督办情况"></el-input>
											</div>
										</div>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item prop="overDeadLine">
										<div class="content">
											<my-tooltip text="完成时限"></my-tooltip>
											<div class="desc-input">
												<el-date-picker type="date" format="yyyy-MM-dd" v-model="dataAll.overDeadLine" placeholder="选择日期" style="width: 100%;"></el-date-picker>
											</div>
										</div>
									</el-form-item>
								</el-col>
								<el-col :span="12"></el-col>
								<el-col :span="12">
									<el-form-item prop="responseUnit">
										<my-tooltip text="督办单位"></my-tooltip>
										<div class="desc-input">
											<el-select v-model="dataAll.responseUnit" multiple placeholder="请选择">
												<el-option v-for="item in unitList" :key="item.id" :label="item.name" :value="item.id">
												</el-option>
											</el-select>
										</div>

									</el-form-item>
								</el-col>
							</el-row>
							<div style="text-align:left; margin-left:100px;">
								<el-button type="primary" @click="upate('dataAll')" style="width:130px">保存</el-button>
								<el-button @click="dialogVisible = false" style="width:130px;margin-left:20px">取消</el-button>
							</div>
						</div>
					</el-form>
				</el-tab-pane>
			</el-tabs>
		</el-dialog>
	</div>
</template>
<script>
	export default {
		props: ['showDialogId'],
		created() {
			this.ajax({
				url: 'tDictionary/selectDictionaryByCode',
				data: {
					code: 'P1'
				}
			}).then(data => {
				this.unitList = data;
				this.queryInfo()
			})
			//      this.ajax({
			//              url: 'Area/GetByParentCode',
			//              data: {
			//                  parentCode: "511500"
			//              }
			//          }).then(data => {
			//              this.areaList = data
			//      })

		},
		mounted() {

		},
		watch: {
			dialogVisible(val) {
				this.$emit('update:showDialog', val)
			}
		},
		data() {
			return {
				dialogVisible: true, //弹出框隐藏显示
				options: [],
				unitList: [],
				value: '',
				dataAll: {},
				areaList: [],
				rules: {
					workContent: [{
						required: true,
						message: '督办情况不能为空',
						trigger: 'blur'
					}],
				},
			}
		},
		methods: {
			queryInfo() {
				this.ajax({
					url: 'tProjectSupervisor/selectProjectSupervisorById',
					data: {
						id: this.showDialogId
					}
				}).then(data => {
					data[0].responseUnit = this.formateData(data[0].responseUnit);
//					debugger
//					if(data[0].overDeadline){
//						debugger
//						data[0].overDeadline=new Date(data[0].overDeadline.substring(0,10));
//					}
					console.log(data[0])
					this.dataAll = data[0]
				})
			},
			formateData(responseUnits) {
				var selectunits = [];
				if(responseUnits) {
					var responseunits = responseUnits.split(',');
					for(var i = 0; i < responseunits.length; i++) {
						if(responseunits[i]) {
							selectunits.push(parseInt(responseunits[i]));
						}
					}
				}

				return selectunits;
			},
			show(row) {
				this.dialogVisible = !this.dialogVisible
			},
			upate(formName) {
				//this.dataAll.pId = this.projectId;
				this.dataAll.overDeadLine = this.formatedate(this.dataAll.overDeadLine);
				this.dataAll.responseUnit = this.dataAll.responseUnit.join(',');
				this.$refs[formName].validate((valid) => {
					if(valid) {
						this.ajax({
							url: 'tProjectSupervisor/editProjectSupervisor',
							type: 'post',
							data: this.dataAll,
						}).then(data => {
							/*向上传递修改成功的信息*/
							this.eventBus.$emit('workUpdate')
							this.dialogVisible = false
						})
					}
				});
			},
			formatedate(time) {
				var d = new Date(time);
				if(!d.getFullYear()) {
					return null;
				}
				return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + '00:00:00';
			}
		},
		components: {

		}
	}
</script>
<style lang="less">
	.streetEdit .el-form-item__error {
		top: 35px;
		left: 100px;
	}
	
	.streetEdit .el-form-item {
		min-height: 50px;
		margin-bottom: 5px;
	}
</style>
<style scoped lang="less">
	.zui-noFloat .el-col {
		float: none;
		display: inline-block;
		margin-right: -4px;
		vertical-align: top;
	}
	
	.projectDialog .desc-input {
		width: 70%;
		float: left;
	}
</style>